# coding: utf-8

from sqlalchemy import Column, Integer, String, JSON, DATETIME
from sqlalchemy.ext.declarative import declarative_base

from bluesky.util import biz

Base = declarative_base()


class Resource:
    __tablename__ = ''

    id = Column('id', String(60), primary_key=True)
    name = Column('name', String(100))
    parent_id = Column('parent_id', String(100))
    type = Column('type', String(45))
    ext = Column('ext', JSON())
    is_delete = Column('is_delete', Integer)
    status = Column('status', Integer)
    creator = Column('creator', String(45))
    creator_nickname = Column('creator_nickname', String(45))
    created_time = Column('created_time', DATETIME)
    updated_time = Column('updated_time', DATETIME)
    deleted_time = Column('deleted_time', DATETIME)

    def __init__(self):
        self.id = None
        self.name = None
        self.parent_id = None
        self.type = None
        self.ext = None
        self.is_delete = None
        self.status = None
        self.creator = None
        self.creator_nickname = None
        self.created_time = None
        self.updated_time = None
        self.deleted_time = None

    def __repr__(self):
        return "<Resource(id='%s', name='%s', parent_id='%s', type='%s', is_delete='%s', status='%s', " \
               "creator='%s', creator_nickname='%s', ext='%s', created_time = '%s', updated_time = '%s')>" % (
                   self.id, self.name, self.parent_id, self.type, self.is_delete, self.status, self.creator,
                   self.creator_nickname, self.ext, self.created_time, self.updated_time)


# @dataclass
class ResourceApi(Resource, Base):
    __tablename__ = 'resource_api'


# @dataclass
class RImg(Resource, Base):
    __tablename__ = 'r_img'


# @dataclass
class RConfig(Resource, Base):
    __tablename__ = 'r_config'


for cls in Resource.__subclasses__():
    biz.table_rs_cls_map[cls.__tablename__] = cls
